<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>

<jsp:useBean id="nowDate" class="java.util.Date" />
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/logic/sowarefreezedeal";
var grid;

var ItemStateList = ItemStateData.Rows;//物料等级列表

$(function(){
 
	//表格结构
	var griddata ={};
	grid = $("#table1").ligerGrid({
        columns: [{ display: '操作',width: 30,
		    	render: function (record, rowindex, value, column) {
		    		var rc = JSON.stringify(record);
				  	  if(record.openBatch=='Y'){
				  		 return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'><img src='${ctx}/js/ligerUI/skins/icons/add.gif' alt='添加' /></a>";
				  	  }else{
				  		 return "<h1>+</h1>";
				  	  }
					  }},
                  { display: 'ID', name: 'id', width: 1 , hide:true},
                  { display: '产品id', name: 'materialsid', width: 1 , hide:true},//使用selecturl时必须设置该属性
				  {display : '产品编码',name : 'code',width : 1,hide:true,//不保存
					render:function(item){
						item.code=item.prodNo; 
						return item.code;
					}
				  }, 
                  { display: '<font color="gray">产品编码</font>', name: 'prodNo', width: 100,
					  render: function (record, rowindex, value, column) {
						  var rc = JSON.stringify(record);
						  if(record.openBatch=='Y'){
							  return "<a href='javascript:ItemWindow("+rc+","+rowindex+")'>"+record.code+"</a>";
						  	  }else{
						  		 return record.code;
						  	  }
					  	  
					  }},
				  { display: '<font color="gray">产品名称</font>', name: 'prodName', width: 80 },
				  { display: '<font color="gray">型号规格</font>', name: 'prodSpecDesc', width: 120 },
				  { display: '<font color="gray">物料是否可用批次</font>', name: 'openBatch' ,hide:true,width: 150, render: function (item, rowindex, value, column)
					    {
	            	   	if(item.openBatch=="Y"){
	            	   		return "可用";
	            	   	}else{
	            	   		return "不可用";
	            	   	}
				   		
			    }},
				  { display: '<font color="gray">基本单位</font>', name: 'prodBUnit', width: 80},
				  { display: '<font color="gray">单位换算率</font>', name: 'prodUnitConvert', width: 70,render:function(item){
						changequantity(item);
						return item.prodUnitConvert;
					}},
				  { display: '单位<font color="red">*</font>', name: 'prodUnit', width: 70,editor : {
		          	  type:'selecturl',dataItem:'dataItem',path:'${ctx}/yd/basic/measurementUnit/unitlist.do',valueColumnName: 'unitname',displayColumnName: 'unitname', displayColumnName: 'unitname',onChanged:function(record,value,column,rowindex,datagrid){
		            	  grid.updateCell('itemBatch', '', record);
		            	  grid.updateCell('djQuantity', '', record);
		            	  grid.updateCell('djBQuantity', '', record);
		            	  }}, render: function (item)
		                   {
		        	 		  var dataitem = $.parseJSON($("#dataItem").val());
		        	 		  if(dataitem!=null){
		        	 			 for (var i = 0; i < dataitem.length; i++)
		                         {
		                             if (dataitem[i]['unitname'] == item.prodUnit&&dataitem[i]['materialscode']==item.prodNo){
		                           	  	 grid.updateCell('prodUnitConvert', dataitem[i]['unitconvert'], item);
		                           	  	 return dataitem[i]['unitname'];
		                                
		                             } 
		                         }
		        	 		  }
		                       return item.prodUnit;
		                   } },
// 				  { display : '产品批次<font color="red">*</font>',name : 'prodBatch',width : 80, isSort: false
// 					  //<c:if test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
// 					  ,editor: { /*onChanged:getkcQuantity,*/type: 'selectbatch',whcode:'whcode', databatch:'batchItem',path:'${ctx}/yd/logic/otherOutwh/getWhBatch.do', valueColumnName: 'batch', displayColumnName: 'batch',
// 				   			ext:function (rowdata)
// 			                {
// 			                    return {
// 			                        onBeforeOpen: function(){
// 			                        	if(undefined==$("#whcode").val() || ""==$("#whcode").val()){
// 			                    			$.dialog.alert("请先选择仓库");
// 			                    			return ;
// 			                    		}
// 			                        	getDG().dialog({
// 								    		title:'选择批次',
// 								    		width : 300,
// 											height : 350,
// 											content: 'url:' + sys_context+'/public/windowalert/itembatch.do?whCode=' + $("#whcode").val()+'&maCode='+rowdata.prodNo,//
// 								    		lock : true,
// 								    		max : true,
// 								    		min : true,
// 								    		ok: function(){
// 								    			var rows = this.content.getSelected();
// 												if (rows != null) {
// 													grid.updateCell('prodBatch', rows[0].batch, rowdata);
// 													grid.endEdit();
// 													getBatchkcQuantity(rowdata);//修好后的触发
// 												}
// 												this.content.Close();
// 								        		return false;
// 								    	    },
// 								    	    cancelVal: '关闭',
// 								    	    cancel: function(){
// 								    	    	grid.endEdit();
// 								    	    } 
// 								    	}).zindex();
// 			                        }, render: function ()
// 			                        { 
// 			                        	var batchItem = $.parseJSON($("#batchItem").val());
// 			            		  		if(batchItem!=null){
// 			            			 	for (var i = 0; i < batchItem.length; i++)
// 			                     			{
// 			                         			if (batchItem[i]['batch'] == rowdata.prodBatch){
// 			                            	 		return batchItem[i]['batch'];
// 			                         			} 
// 			                     			}
// 			            		  		}
// 			                        }

// 			                    };
// 			                }
// 				   		},
// 				   		render: function (item){
// 			   		 		var batchItem = $.parseJSON($("#batchItem").val());
// 					  		if(undefined != batchItem && "" != batchItem){
// 						 	for (var i = 0; i < batchItem.length; i++)
// 			         			{
// 			             			if (batchItem[i]['batch'] == item.prodBatch){
// 			                	 		return batchItem[i]['batch'];
// 			             			} 
// 			         			}
// 					  		}
// 			                return item.prodBatch;
// 			            }
// 				   		//</c:if>
// 					}, 
					{ display: '<font color="gray">等级</font>', name: 'status', width: 60
						,render: function (item){
		            		  var state=item.status;
		            		  if(state=="1"){
		            			  return "一等品";
		            		  }
		            		  if(state=="2"){
		            			  return "次品";
		            		  }
		            		  if(state=="3"){
		            			  return "旧件";
		            		  }
		            	  	}
					},
					{display : '可用库存基本单位数量</font>',name : 'kyBQuantity',width : 1 , hide:true},
					{display : '<font color="gray">可用库存数量</font>',name : 'kyQuantity',width : 100},
					
					{display : '<font color="gray">本单可冻结数量</font>',name : 'tmpCanFrozenQuantity',width : 100
						,render:function(item){
							item.tmpCanFrozenQuantity =
								item.sqdjQuantity - item.sjdjQuantity;
							return item.tmpCanFrozenQuantity+"";
						  }
				   },
					
					{ display: '<font color="gray">实际冻结基本单位数量</font>', name: 'djBQuantity', width:1 , hide:true},
	                  { display: '实际冻结数量<font color="red">*</font>', name: 'djQuantity', width: 80
	                	//<c:if test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
	                	  ,editor: { type: 'float'},
	                	  render:function(item){
	                		  if(item.openBatch=="Y"){
			            	   		item.djQuantity=item.val;
			            	   	}else{
		        					if(!isNaN(item.djQuantity) && !isNaN(item.prodUnitConvert)){
		        			    		item.djBQuantity = item.djQuantity*item.prodUnitConvert ;
		        			    	}else{
		        			    		item.djBQuantity = null;//清除值
		        			    	}
			            	   	}
	        				  return item.djQuantity;
	        			  	}
	                	//</c:if>
 	                  },
	                  
	                  { display: '冻结出库基本单位数量', name: 'djckBQuantity', width: 1 , hide:true},
	                  { display: '<font color="gray">本单冻结出库数量</font>', name: 'djckQuantity', width: 100,
	                	  render:function(item){
	      					if(undefined == item.djckQuantity || null == item.djckQuantity || isNaN(item.djckQuantity) ){
	      			    		item.djckQuantity = 0;
	      			    		item.djckBQuantity = 0;
	      			    	}
	      					
	      				  return item.djckQuantity+"";
	      			  	}
	                  },
	                  
	                  { display: '解冻基本单位数量', name: 'djjdBQuantity', width: 1 , hide:true},
	                  { display: '<font color="gray">本单解冻数量</font>', name: 'djjdQuantity', width: 90,
	                	  render:function(item){
	      					if(undefined == item.djjdQuantity || null == item.djjdQuantity || isNaN(item.djjdQuantity) ){
	      			    		item.djjdQuantity = 0;
	      			    		item.djjdBQuantity = 0;
	      			    	}
	      					
	      				  return item.djjdQuantity+"";
	      			  	}
	                  },
				  
				  { display: '<font color="gray">申请冻结基本单位数量</font>', name: 'sqdjBQuantity', width: 150},
                  { display: '<font color="gray">申请冻结数量</font>', name: 'sqdjQuantity', width: 80},
                  { display: '<font color="gray">已冻结基本单位数量</font>', name: 'sjdjBQuantity', width: 1 , hide:true},
                  { display: '<font color="gray">已冻结数量</font>', name: 'sjdjQuantity', width: 90},
                  
                  { display: '订单基本单位数量', name: 'prodBQuantity', width: 1 , hide:true},
				  { display: '<font color="gray">订单数量</font>', name: 'prodQuantity', width: 80},
				  
				  { display: '<font color="gray">已出库基本单位数量</font>', name: 'ckBQuantity', width: 150},
                  { display: '<font color="gray">已出库数量</font>', name: 'ckQuantity', width: 80/* , type: 'float' */},
                  { display: '<font color="gray">订单已冻结基本单位数量</font>', name: 'frozenBQuantity', width: 150},
                  { display: '<font color="gray">订单已冻结数量</font>', name: 'frozenQuantity', width: 90},
                  { display: '<font color="gray">值</font>', name: 'val' ,width:1,hide:1},
                  
                  
                  { display: '备注', name: 'remark', width: 150
                	//<c:if test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
                  	,editor: { type: 'text'},
                	//</c:if>
                  },
                  { display: '<font color="gray">批次信息</font>', name: 'itemBatch', width:1,hide:1}
//                   { display: '分多批操作',width: 150,
//             	        render: function (record, rowindex, value, column) {
//              		  	   return "<a href='javascript:manyBatch(" + rowindex + ")'>分多批次</a>";
//              		  }}
                  ],
                  enabledEdit: true,
                  usePager: true,pageSize:1000,pageSizeOptions:[1000],
                  //data : griddata,
                  parms:[{ name : 'id' , value : '${soware.id}'}],
                  url : basic_Url+"/griditems.do",
                  width: "100%", height:'90%',
                  checkbox : true
                //<c:if test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
                  ,toolbar : {
      				items : [{
      					line : true
      				}, {
      					text : '删除',
      					click : deleteRow,
      					img : '${ctx}/js/ligerUI/skins/icons/delete.gif'
      				} ]
      			  }
                //</c:if>
     });
	
	//表格数据加载
	/* var manager = $("#table1").ligerGetGridManager();
	//<c:forEach items='${sowareitem}' var='item'>
    	manager.addRow2({
    		id : "${item.id}" ,
    		materialsid:"${item.materialsid}",
    		prodNo :"${item.prodNo}",
    		prodBatch :"${item.prodBatch}",
    		prodName: "${item.prodName}",
    		prodSpecDesc :"${item.prodSpecDesc}",
    		status :"${item.status}",
    		prodBUnit :"${item.prodBUnit}",
    		prodUnit :"${item.prodUnit}",
    		prodUnitConvert:"${item.prodUnitConvert}",
    		
    		prodBQuantity :"${item.prodBQuantity}",
    		prodQuantity :"${item.prodQuantity}",
    		
    		kyBQuantity :"${item.kyBQuantity}",
    		kyQuantity :"${item.kyQuantity}",
    		ckBQuantity :"${item.ckBQuantity}",
    		ckQuantity :"${item.ckQuantity}",
    		
    		frozenBQuantity :"${item.frozenBQuantity}",
    		frozenQuantity :"${item.frozenQuantity}",
    		
    		sqdjBQuantity :"${item.sqdjBQuantity}",
    		sqdjQuantity :"${item.sqdjQuantity}",
    		
    		sjdjBQuantity :"${item.sjdjBQuantity}",
    		sjdjQuantity :"${item.sjdjQuantity}",
    		
    		djBQuantity :"${item.djBQuantity}",
    		djQuantity :"${item.djQuantity}",
    		
    		djjdBQuantity :"${item.djjdBQuantity}",
   			djjdQuantity :"${item.djjdQuantity}",
    		
    		djckBQuantity :"${item.djckBQuantity}",
    		djckQuantity :"${item.djckQuantity}",
    		remark :"${item.remark}",
    		itemBatch:'${item.itemBatch}',
    		openBatch: "${item.openBatch}",
    		val : "${item.val}"
        });
    //</c:forEach> */
	
	//表单提交验证
	$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
            getReturnMessage(url,"inputForm",W.searchAP);
        }catch(e){alert(e);}
    }
	});
	
	//按钮处理
	/* btn status */
	$("[id^='btn_fb_']").hide();
	var curStatus = "${soware.billstatus}";//当前所在环节、状态
	if(curStatus == ''){//建单
		$("#btn_fb_save").show();
	}else {
		//$("#btn_fb_exportExcel").show();
		formComponentDisabled(true);//禁用控件
		if (curStatus == '0'||curStatus == '3'){//草稿状态-提交二级
			if("${user.name}"=="${soware.dcruser}"){
				$("#btn_fb_approve_2").show();
				$("#btn_fb_cancel").show();
			}
			formComponentDisabled(false);//启用控件
		}else if (curStatus == '1'){//二级审批中状态
			$("#btn_fb_rebut_2").show();
			$("#btn_fb_end_2").show();
		}else if (curStatus == '4'){//取消状态
		}else{
		}
	}
	
	//添加模式隐藏DIV
	if("${flag}" =="ADD"){
		$("#tr1").hide();
		//$("#tr2").hide();
	}
	
	//页面加载标识隐藏
	$("#pageloading").hide();

	//=============================
		
    	//销售订单的值改变触发
    	$("#sowarefreezeNo").change(function(){ 
    		var tmpVal = $(this).val();
       		
       		$.ajax({
  		      url: basic_Url+"/getSowarefreeze.do",
  		      global: false,
  		      type: "POST",
  		      dataType: "json",
  		      data: ({
  		    	sowarefreezeNo : tmpVal
  		      }), 
  		      success: function(o){
  		    	  var tmpBean = o.bean;
  		    	  if(undefined !=tmpBean && null != tmpBean){
  		    		$("#soNo").val(tmpBean.soNo);
  		    		$("#cliOrderNo").val(tmpBean.cliOrderNo);
  	        		$("#cliName").val(tmpBean.cliName);
  	        		$("#cliNo").val(tmpBean.cliNo);
  	        		$("#cliAddr").val(tmpBean.cliAddr);
  	        		$("#cliPeo").val(tmpBean.cliPeo);
  	        		$("#cliTel").val(tmpBean.cliTel);
  	        		$("#cliFax").val(tmpBean.cliFax);
  	        		//$("#receipDate").val('');
  	        		$("#payMode").val(tmpBean.payMode);
  	        		$("#deliveryMode").val(tmpBean.deliveryMode);
  	        		$("#currency").val(tmpBean.currency);
  	        		$("#exchangeRate").val(tmpBean.exchangeRate);
  	        		if(undefined != tmpBean.deliveryDate && null != tmpBean.deliveryDate && "" != tmpBean.deliveryDate){
  	        			$("#deliveryDate").val(new Date(tmpBean.deliveryDate).formatdt('yyyy-MM-dd'));
  	        		}else{
  	        			$("#deliveryDate").val("");
  	        		}
  	        		
  	        		
  	  		    	multipleSearch("#table1",true,"",basic_Url+"/sowarefreezeitemlist.do?sowarefreezeId="+tmpBean.id);
  		    	  }else{
  		    		  
  		    	  }
  		      }
  	   		});
       		
    	});
    	
    	//仓库下拉列表改变触发
    	$("#storage").change(function(){ 
    		var data = grid.getData();
    		var code="";
    		if (data.length == 0) {
    			$.dialog.alert("请选择销售单号");
    			return false;
    		}else{
    			for(var i=0;i<data.length;i++){
    				if(i==0){
    					code=data[i].code;
    				}else{
    					code+=","+data[i].code;
    				}
//     				grid.updateRow(rowData,{kyQuantity:"1111"});
//     				if((item.status!=null)&&(undefined!=$("#whcode").val() && ""!=$("#whcode").val())){
// 						$.ajax({
// 			     		      url: "${ctx}/yd/logic/otherOutwh/getStorageQuaitity.do",
// 			     		      global: false,
// 			     		      type: "POST",
// 			     		      dataType: "json",
// 			     		      data: ({
// 			     		    	maCode : item.code,
// 			     				whCode : $("#whcode").val(),
// 			     				hubCode : "",
// 			     				status : item.status,
// 			     				batch : "NoBatch"
// 			     		      }),		     
// 			     		      success: function(msg){
// 			     		    	 item.kyBQuantity = msg;
// 			     		    	item.auto = true;
// 			     	   			grid.updateCell('kyBQuantity',msg,item);
// 			     	   			if(!isNaN(item.prodUnitConvert)){
// 			     	   			item.kyQuantity = (item.kyBQuantity / item.prodUnitConvert);
// 			 		    			grid.updateCell('kyQuantity',item.kyQuantity,item);
// 			     	   			}
			     	   			
// 			     		      }
// 			     	   });
// 					}
    			}
    		}
    		  $("#whcode").val($("#storage").val());
    		  $("#whname").val($("#storage").find("option:selected").text());
    		  
    		  //表格中批次、等级、可用库存
    		  var len = grid.rows.length;
    		  for(var i=0 ; i<len;i++){
    			  var rowData = grid.rows[i];
    			  //rowData.prodBatch="";
    			  //grid.updateCell('prodBatch',rowData.kyQuantity,rowData);
    			  grid.updateRow(rowData,{prodBatch:""});
    			 if(rowData.openBatch!="Y"){
	  				if((rowData.status!=null)&&(undefined!=$("#whcode").val() && ""!=$("#whcode").val())){
							$.ajax({
				     		      url: "${ctx}/yd/logic/otherOutwh/getStorageQuaitity.do",
				     		      global: false,
				     		      type: "POST",
				     		      dataType: "json",
				     		      data: ({
				     		    	maCode : rowData.code,
				     				whCode : $("#whcode").val(),
				     				hubCode : "",
				     				status : rowData.status,
				     				batch : "NoBatch"
				     		      }),		     
				     		      success: function(msg){
				     		    	 if(msg==null || ""==msg){
				     		    		rowData.kyBQuantity = 0;
				     		    	 }else{
				     		    		rowData.kyBQuantity = msg;
				     		    	 }
				     		    	
				     		    	rowData.auto = true;
				     	   			grid.updateCell('kyBQuantity',msg,rowData);
				     	   			if(!isNaN(rowData.prodUnitConvert)){
				     	   			rowData.kyQuantity = (rowData.kyBQuantity / rowData.prodUnitConvert);
				 		    			grid.updateCell('kyQuantity',rowData.kyQuantity,rowData);
				     	   			}
				     	   			
				     		      }
				     	   });
						}
    			  }
    		  }
    		  
    		  
    	});
    
});

function changequantity(item){
	if(undefined == item){
   		return;
   	}
	//销售订单数量
   	if(!isNaN(item.prodBQuantity) && item.prodBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.prodQuantity = item.prodBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//申请冻结数量
   	if(!isNaN(item.sqdjBQuantity) && item.sqdjBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.sqdjQuantity = item.sqdjBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//冻结出库数量
   	if(!isNaN(item.djckBQuantity) && item.djckBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.djckQuantity = item.djckBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//冻结解冻数量
   	if(!isNaN(item.djjdBQuantity) && item.djjdBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.djjdQuantity = item.djjdBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//已经冻结数量
   	if(!isNaN(item.sjdjBQuantity) && item.sjdjBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.sjdjQuantity = item.sjdjBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//出库数量
   	if(!isNaN(item.ckBQuantity) && item.ckBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.ckQuantity = item.ckBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
	//订单已经冻结数量
   	if(!isNaN(item.frozenBQuantity) && item.frozenBQuantity!=null&&item.prodUnitConvert!=null&&item.prodUnitConvert!=''){
   		item.frozenQuantity = item.frozenBQuantity/parseFloat(item.prodUnitConvert) ;
   	}
}
	//按钮提交前处理
	function submitForm(param) {
		//设置ajax全局同步
		$("#paramflag").val(param);

		var data = grid.getData();
		var dl = grid.getDeleted();
		if (data.length == 0) {
			$.dialog.alert("请选择申请产品");
			return false;
		}
		
		var ba = true;
		
		if(data !=null){
			var j=0;
			$(data).each(function (){
				j++;
				//表格必填项
				
// 				if (undefined == this.prodBatch
// 						|| "" == this.prodBatch) {
// 					$.dialog.alert("第" + j + "行的“产品批次”数据不合法");
// 					ba = false;
// 					return false;
// 				}
				
// 				if (undefined == this.status
// 						|| "" == this.status) {
// 					$.dialog.alert("第" + j + "行的“产品等级”数据不合法");
// 					ba = false;
// 					return false;
// 				}
				if(this.openBatch!="Y"){
					if (undefined == this.djQuantity
							|| isNaN(this.djQuantity)
							|| this.djQuantity <= 0) {
						$.dialog.alert("第" + j + "行的“实际冻结数量”数据不合法");
						ba = false;
						return false;
					}
					//alert(parseFloat(this.kyQuantity));
					if(parseFloat(this.kyQuantity) < parseFloat(this.djQuantity)){
						$.dialog.alert("第" + j + "行的实际冻结数量大于可用库存数量");
						ba = false;
						return false;
					}
					if(/* (this.sqdjQuantity - this.sjdjQuantity) */
							this.tmpCanFrozenQuantity < this.djQuantity){
						$.dialog.alert("您第" + j + "的冻结数量大于冻结申请单据可冻结数量");
						ba = false;
						return false;
					}
				}
				
// 				var tmpSoCanFreezonQty = this.prodQuantity - this.ckQuantity - this.frozenQuantity;
// 				if(tmpSoCanFreezonQty< this.djQuantity){//无用的验证？
// 					$.dialog.alert("您第" + j + "的冻结数量大于销售订单可冻结数量");
// 					ba = false;
// 					return false;
// 				}
				
				
				
				
			});
// 			for ( var i = 0; i < data.length; i++) {
// 				var num =parseFloat(data[i].djQuantity);
// 				for ( var j = 0; j < data.length; j++) {
// 					if(i != j){
// 						if(data[i].prodNo==data[j].prodNo && data[i].prodBatch==data[j].prodBatch && data[i].status==data[j].status){
// 							ba = false;
// 							$.dialog.alert("物料编码为:" + data[j].prodNo + "的第"+(i+1)+"行与第"+(j+1)+"行存在相同的批次与等级!");
// 							return false;
// 						}else if(data[i].prodNo==data[j].prodNo){
// 							num +=parseFloat(data[j].djQuantity);
// 							if(num>parseFloat(data[i].tmpCanFrozenQuantity)){
// 								alert("num:"+num);
// 								alert("data[i].tmpCanFrozenQuantity:"+data[i].tmpCanFrozenQuantity);
// 								ba = false;
// 								$.dialog.alert("物料编码为:" + data[j].prodNo + "的“实际冻结数量”大于“本单可冻结数量”");
// 								return false;
// 							}
// 						}
// 					}
// 				}
// 			}
		}
		
		jQuery.ajaxSettings.async = false;
		if (ba) {
			$("#itemdata").val(JSON.stringify(data));
			$("#itemdelete").val(JSON.stringify(dl));
			$("#submitFlag").val(param);
			formComponentDisabled(false);//启用控件
			$("#inputForm").submit();
		}
	}
	
	function tableSubmit(msg,param){
		$.ligerDialog.confirm(msg, 
				function (flag) { 
				if(flag){
					submitForm(param);
					}
			}); 
	}
	
	function submitFormClose(param){
		tableSubmit('是否确认关闭单据操作？',param);
	}
	
	function submitFormEnd(param){
		tableSubmit('是否确认审批完结操作？',param);
	}
	
	function submitFormRebut(param){
		tableSubmit('是否确认驳回操作？',param);
	}
	
	
	function deleteRow() {
		grid.deleteSelectedRow();
	}
	
	function exportExcel() {
		var path = basic_Url + "/exportExcel.do?id=${soware.id}";
		window.open(path, "_blank");
	}
	
	/**
	 * 获取库存数量
	 */
    function getkcQuantity(e){
    	var rowData=grid.getRow($(e).parent()[0]);
    	getBatchkcQuantity(rowData);
    }
	
    /**
	 * 获取库存数量2
	 */
	function getBatchkcQuantity(rowData){
		if(undefined==$("#whcode").val() || ""==$("#whcode").val()){
			$.dialog.alert("请先选择仓库");
			return ;
		}
		if (rowData.prodBatch){
   		 $.ajax({
     		      url: "${ctx}/yd/logic/otherOutwh/getStorageQuaitity.do",
     		      global: false,
     		      type: "POST",
     		      dataType: "json",
     		      data: ({
     		    	maCode : rowData.code,
     				whCode : $("#whcode").val(),
     				hubCode : "",
     				status : rowData.status,
     				batch : rowData.prodBatch
     		      }),		     
     		      success: function(msg){
     		    	rowData.kyBQuantity = msg;
     		    	rowData.auto = true;
     	   			grid.updateCell('kyBQuantity',msg,rowData);
     	   			if(!isNaN(rowData.prodUnitConvert)){
 		    			rowData.kyQuantity = (rowData.kyBQuantity / rowData.prodUnitConvert);
 		    			grid.updateCell('kyQuantity',rowData.kyQuantity,rowData);
     	   			}
     	   			
     		      }
     	   });
  		}else{
  			$.dialog.alert("请先选择批次");
  		}
    }
   
// 	function manyBatch(index){
// 		var data= grid.getData();
// 		var manager = $("#table1").ligerGetGridManager();
// 		manager.addRow2(data[index]);
// 	}
function ItemWindow(rc,index) {
 	if(undefined==$("#whcode").val() || ""==$("#whcode").val()){
			$.dialog.alert("请先选择仓库");
			return ;
	}
 	var manager = $("#table1").ligerGetGridManager();
		getDG().dialog(
				{
					title : '批次管理',
					width : 650,
					height : 350,
					content : 'url:' + sys_context+ '/yd/logic/sowarefreezedeal/itemManager.do?data='+encodeURIComponent(JSON.stringify(manager.getRow(rc.__index)))+'&billstatus=${soware.billstatus}'+'&whcode='+$("#whcode").val(),//
					lock : true,
					max : true,
					min : true,
					ok : function() {
						this.content.yz();
						if(this.content.ba){
						var dt = this.content.grid.getData();
						if (dt != null) {
							rc.djBQuantity=this.content.jnum;
							rc.djQuantity=this.content.num;
							rc.kyBQuantity=this.content.kyBQuantity;
							rc.kyQuantity=this.content.kyQuantity;
							rc.val=this.content.num;
							rc.itemBatch=JSON.stringify(dt);
									grid.updateCell('djBQuantity', rc.djBQuantity, manager.getRow(rc.__index));
									grid.updateCell('djQuantity', rc.djQuantity, manager.getRow(rc.__index));
									grid.updateCell('val', rc.val, manager.getRow(rc.__index));
									grid.updateCell('itemBatch',rc.itemBatch, manager.getRow(rc.__index));
									grid.updateCell('kyBQuantity',rc.kyBQuantity, manager.getRow(rc.__index));
									grid.updateCell('kyQuantity',rc.kyQuantity, manager.getRow(rc.__index));
									grid.updateRow(manager.getRow(rc.__index));
									this.content.Close();
							}else{
								this.content.Close();
							}
							
						}
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
	}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${soware.id}"/>
<input type="hidden" id="version" name="version" value="${soware.version}"/>
<input type="hidden" id="itemdata" name="itemdata" value=""/>
<input type="hidden" id="dataItem" name="dataItem"/><!-- 单位获取辅助 -->
<input type="hidden" id="batchItem" name="batchItem"/><!-- 列表产品批次json -->
<input type="hidden" id="itemdelete" name="itemdelete" value=""/>
<input type="hidden" id="paramflag" name="paramflag" value=""/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         			<tr id="tr1">
   		           		<td nowrap="nowrap" width="20%">单据编号:</td>
   		                <td width="30%">
   		                	<input type="text" id="no" name="no" value="${soware.no}" class="inp_width_98p required" readonly="readonly"/>
   		                </td>
   		                <td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%"><input type="text" id="dctime" name="dctime" class="inp_width_98p" 
							value="<fmt:formatDate value="${empty soware.dctime?nowDate:soware.dctime}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/></td>
   		           </tr>
                   <tr>
                    	<td nowrap="nowrap">冻结申请单编号:</td>
						<td>
						<c:choose>
						<c:when test="${'ADD' eq flag}">
						<select id="sowarefreezeNo" name="sowarefreezeNo" class="inp_width_98p required" >
							<option> </option>
							<c:forEach items="${swflist}" var="sodo">
								<option value="${sodo.no}">${sodo.no}</option>
							</c:forEach>
						</select>
						<script type="text/javascript">
   		                	$("#sowarefreezeNo").val("${soware.sowarefreezeNo}");
   		                </script>
						</c:when>
						<c:otherwise>
						<input type="text" value="${soware.sowarefreezeNo}" id="sowarefreezeNo" name="sowarefreezeNo" class="inp_width_98p required" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
						<input type="hidden" id="soNo" name="soNo" value="${soware.soNo}" readonly="readonly"></input>
   		            	</td>
                    	<td nowrap="nowrap">客户编号:</td>
   		           		<td><input type="text" id="cliNo" name="cliNo" value="${soware.cliNo}" class="inp_width_98p required" readonly="readonly"></input></td>
   		           		
   		           </tr>
   		           <tr>
   		                <td nowrap="nowrap">客户单位名称:</td>
   		           		<td><input type="text" id="cliName" name="cliName" value="${soware.cliName}" class="inp_width_98p required" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">客户联系人:</td>
   		           		<td><input type="text" id="cliPeo" name="cliPeo" value="${soware.cliPeo}" class="inp_width_98p" readonly="readonly"></input></td>
   		           		
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">联系电话:</td>
   		           		<td><input type="text" class="inp_width_98p" id="cliTel" name="cliTel" value="${soware.cliTel}" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">传真:</td>
   		           		<td><input type="text" class="inp_width_98p" id="cliFax" name="cliFax" value="${soware.cliFax}" readonly="readonly"></input></td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">客户地址:</td>
   		            	<td colspan="3">
   		                	<input class="inp_width_98p" type="text" id="cliAddr" name="cliAddr" value="${soware.cliAddr}" readonly="readonly"/>
   		             	</td>
   		           </tr>
   		           <tr>
   		           		<td nowrap="nowrap">冻结仓库:</td>
						<td >
						<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
							<select id="storage" name="storage" class="inp_width_98p required">
   		                 	<option></option>
   		                 	<c:forEach items='${wh}' var='state'>
   		                 	<option value='${state.code}'>${state.name}</option>
   		                 	</c:forEach>
   		                 	</select>
   		                 	<script type="text/javascript">
   		                		$("#storage").val("${soware.whcode}");
   		                 	</script>
   		                 	
   		                </c:when>
						<c:otherwise>
						<input type="text" value="${soware.whname}" id="storage" name="storage" class="inp_width_98p" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
						
						<input type="hidden" id="whcode" name="whcode" value="${soware.whcode}"/>
   		                <input type="hidden" id="whname" name="whname" value="${soware.whname}"/>
						</td>
   		           		<td nowrap="nowrap">交货时间:</td>
   		           		<td><input type="text" class="inp_width_98p" id="deliveryDate" name="deliveryDate" value="<fmt:formatDate value="${soware.deliveryDate}" pattern="yyyy-MM-dd" type="both" />"  readonly="readonly"></input></td>
   		           </tr>
   		           
   		           <%-- <tr>
   		           		<td nowrap="nowrap">付款方式:</td>
   		           		<td>
						<input type="text" value="${soware.payMode}" id="payMode" name="payMode" readonly="readonly"></input>
   		           		</td>
   		           		<td nowrap="nowrap">交货方式:</td>
   		           		<td>
						<input type="text" value="${soware.deliveryMode}" id="deliveryMode" name="deliveryMode" readonly="readonly"></input>
   		           		</td>
   		           </tr> --%>
   		           <tr>
   		           		<td nowrap="nowrap">制单人:</td>
   		           		<td><input type="text" class="inp_width_98p" id="listerName" name="listerName" value="${empty soware.listerName?user.realName:soware.listerName}" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">制单人部门:</td>
   		           		<td>
   		           		<c:choose>
   		           		<c:when test="${'ADD' eq flag or '0'eq soware.billstatus or '3'eq soware.billstatus }">
   		           		<select id="listerDeptName" name="listerDeptName" class="inp_width_98p">
								<option></option>
								<c:forEach items="${depts }" var="item">
									<option value="${item.depname }">${item.depname}</option>
								</c:forEach>
						</select> 
   		           			<script type="text/javascript">
   		           				$("#listerDeptName").val("${soware.listerDeptName}");
   		           		</script>
   		           		</c:when>
						<c:otherwise>
						<input type="text" value="${soware.listerDeptName}" id="listerDeptName" name="listerDeptName" class="inp_width_98p" readonly="readonly"></input>
						</c:otherwise>
						</c:choose>
   		           		</td>
   		           </tr>
   		           <!-- <tr id="tr2">
   		           		<td nowrap="nowrap">审核人:</td>
   		           		<td><input type="text" id="auditorName" name="auditorName" value="${soware.auditorName}" readonly="readonly"></input></td>
   		           		<td nowrap="nowrap">批准人:</td>
   		           		<td><input type="text" id="approverName" name="approverName" value="${soware.approverName}" readonly="readonly"></input></td>
   		           </tr> -->
   		           <tr>
                    <td nowrap="nowrap">备注:</td>
   		                 <td colspan="3">
   		                <input class="inp_width_98p" type="text" id="remark" name="remark" value="${soware.remark}" />
   		                 </td>
   		           </tr>
                </table>
                <div id="table1"> </div>               
         </div>
         <div class="formBar">
	        <ul>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_save" onclick="submitForm(0)">保存</button></div></div></li>
		        <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_approve_2" onclick="submitForm(1)" title="提交二级审核">提交</button></div></div></li>
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_cancel" onclick="submitFormClose(4)" title="取消订单">取消</button></div></div></li>
		      	
		      	<webres:displaycontroller elementId="LOGIC_SOWAREFREEZEDEAL_2WANJIE" description="销售冻结处理二级完结">
		      	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="btn_fb_end_2" onclick="submitFormEnd(2)" title="二级结案">审核</button></div></div></li>
		      	</webres:displaycontroller>
		      	<webres:displaycontroller elementId="LOGIC_SOWAREFREEZEDEAL_2BOHUI" description="销售冻结处理二级驳回">
		      	<li><div class="button"><div class="buttonContent"><button type="button" id="btn_fb_rebut_2" onclick="submitFormRebut(3)" title="二级驳回到草稿">驳回</button></div></div></li>
		      	</webres:displaycontroller>
		      	
		      	<li><div class="button"><div class="buttonContent"><button type="button" id="btn_fb_exportExcel" class="export" onclick="exportExcel()">导出</button></div></div> </li>
		       <li><div class="button"><div class="buttonContent"><button type="button" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
